#include "stdafx.h"

#include "cairo/cairo-win32.h"
#include "config.h"
#include "surface-cairo.h"

namespace DeepZoomImage
{
	CairoSurface::CairoSurface (int width, int height)
	{
		size[0] = width;
		size[1] = height;
		stride  = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width);
		data    = (unsigned char *) g_malloc0 (height * stride);
	}

	CairoSurface::CairoSurface (int width, int height,unsigned char *buffer)
	{
		size[0] = width;
		size[1] = height;
		stride  = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width);
		data_in = buffer;
		data = NULL;
	}

	CairoSurface::~CairoSurface ()
	{
		if (data)
		{
			g_free (data);
			data = NULL;
		}
	}

	cairo_surface_t * CairoSurface::Cairo ()
	{
		return cairo_image_surface_create_for_data (data_in,
			CAIRO_FORMAT_ARGB32, size[0], size[1], stride);
	}

	void CairoSurface::SetData(unsigned char *buffer)
	{
		if (NULL != buffer)
		{
			data_in = buffer;
		}

	}
};
